package org.ichihamigua.video.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.ichihamigua.common.framework.entity.Result;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.ichihamigua.common.framework.util.RequestUtil;
import org.ichihamigua.common.video.dto.CommitVideoDto;
import org.ichihamigua.common.video.dto.CreateVideoDto;
import org.ichihamigua.common.video.dto.PushVideoDto;
import org.ichihamigua.common.video.entity.VideoEntity;
import org.ichihamigua.common.video.entity.vo.VideoVo;
import org.ichihamigua.video.service.VideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import vo.PageVo;

import java.io.File;

/**
 * @author rainkyzhong
 * @date 2023/10/29 0:57
 */
@RequestMapping("/video")
@RestController
@Slf4j
public class VideoController {

    @Autowired
    private VideoService videoService;

    private RedisTemplate redisTemplate;

    public VideoController(RedisTemplate redisTemplate) {
        this.redisTemplate = redisTemplate;
    }

    //TODO 上传视频接口（需要对接七牛云对象存储）
    @PostMapping("/create")
    public Result<?> createVideo(HttpServletRequest request, @RequestBody CreateVideoDto dto){
        request.getHeader("user");
        Long userId = 1L;
        return videoService.createVideo(
                userId,
                RequestUtil.getIpAddress(request),
                dto
        );
    }

    @PostMapping("/push")
    public Result<?> pushVideo(HttpServletRequest request, PushVideoDto dto,  @RequestParam MultipartFile file){
        return videoService.pushVideo(file,dto);
    }


    @PostMapping("/commit")
    public Result<?> commit(HttpServletRequest request, @RequestBody CommitVideoDto dto){
        return videoService.saveVideo(dto);
    }

    /**
     * 获取视频列表
     * @param categoryId 视频分类
     * @param pageNum 页数
     */
    @GetMapping("/list")
    public Result<PageVo<VideoVo>> getVideoList(HttpServletRequest request, @RequestParam Long categoryId, @RequestParam(required = false) Integer pageNum){
        return videoService.getVideoList(categoryId, pageNum);
    }

}
